package com.ugoodtech.mdcc.client.service;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved
 * Unauthorized copying of this file, via any medium is strictly prohibited
 * Proprietary and confidential
 */

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ugoodtech.mdcc.core.utils.ZxingHandler;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.OutputStream;

@Service
@Transactional(readOnly = true)
public class QRService {


    /**
     * 输出二维码
     *
     * @param outputStream
     */
    public void getQrImage(Object object, OutputStream outputStream) {

        ObjectMapper objectMapper = new ObjectMapper();
        String json = null;
        try {
            json = objectMapper.writeValueAsString(object);
            System.out.println(json);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        if (json != null) {
            ZxingHandler.encode(json, 200, 200, outputStream);
        }

    }


}
